home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / beos / PPBeDevKit.ZIP / PLAYERPR.TAR / PlayerPRO / Source / Import-Export / XM.h < prev   
Encoding:
Text File  |  1998-12-26  |  13.5 KB  |  382 lines

  1. /********************                        ***********************/
  2. //
  3. //    Player PRO 5.0 - DRIVER SOURCE CODE -
  4. //
  5. //    Library Version 5.0
  6. //
  7. //    To use with MAD Library for Mac: Symantec, CodeWarrior and MPW
  8. //
  9. //    Antoine ROSSET
  10. //    16 Tranchees
  11. //    1206 GENEVA
  12. //    SWITZERLAND
  13. //
  14. //    COPYRIGHT ANTOINE ROSSET 1996, 1997, 1998
  15. //
  16. //    Thank you for your interest in PlayerPRO !
  17. //
  18. //    FAX:                (+41 22) 346 11 97
  19. //    PHONE:             (+41 79) 203 74 62
  20. //    Internet:     RossetAntoine@bluewin.ch
  21. //
  22. /********************                        ***********************/
  23.  
  24. /***** Specification of the FastTracker 2- (.XM)-Format: *****/
  25.  
  26. /*
  27.        The XM module format description for XM files version $0104.
  28.  
  29.        By Mr.H of Triton in 1994.
  30.  ============================================================================
  31.  
  32.    ******************************
  33.    *   The XM file structure:   *
  34.    ******************************
  35.  
  36.    Offset Length Type
  37.  
  38.       0     17   (char) ID text: 'Extended module: '
  39.      17     20   (char) Module name, padded with zeroes
  40.      37      1   (char) $1a
  41.      38     20   (char) Tracker name
  42.      58      2   (word) Version number, hi-byte major and low-byte minor
  43.                         The current format is version $0103
  44.  
  45.      60      4  (dword) Header size
  46.      +4      2   (word) Song length (in patten order table)
  47.      +6      2   (word) Restart position
  48.      +8      2   (word) Number of channels (2,4,6,8,10,...,32)
  49.     +10      2   (word) Number of patterns (max 256)
  50.     +12      2   (word) Number of instruments (max 128)
  51.     +14      2   (word) Flags: bit 0: 0 = Amiga frequency table (see below);
  52.                                       1 = Linear frequency table
  53.     +16      2   (word) Default tempo
  54.     +18      2   (word) Default BPM
  55.     +20    256   (byte) Pattern order table
  56.  
  57.                         Patterns:
  58.                         ---------
  59.  
  60.       ?      4  (dword) Pattern header length
  61.      +4      1   (byte) Packing type (always 0)
  62.      +5      2   (word) Number of rows in pattern (1..256)
  63.      +7      2   (word) Packed patterndata size
  64.  
  65.       ?      ?          Packed pattern data
  66.  
  67.                         Instruments:
  68.                         ------------
  69.  
  70.       ?      4  (dword) Instrument size
  71.      +4     22   (char) Instrument name
  72.     +26      1   (byte) Instrument type (always 0)
  73.     +27      2   (word) Number of samples in instrument
  74.  
  75.    If the number of samples > 0, then the this will follow:
  76.  
  77.    !     +29      4  (dword) Sample header size
  78.    !     +33     96   (byte) Sample number for all notes
  79.    !    +129     48   (byte) Points for volume envelope
  80.    !    +177     48   (byte) Points for panning envelope
  81.    !    +225      1   (byte) Number of volume points
  82.    !    +226      1   (byte) Number of panning points
  83.    !    +227      1   (byte) Volume sustain point
  84.    !    +228      1   (byte) Volume loop start point
  85.    !    +229      1   (byte) Volume loop end point
  86.    !    +230      1   (byte) Panning sustain point
  87.    !    +231      1   (byte) Panning loop start point
  88.    !    +232      1   (byte) Panning loop end point
  89.    !    +233      1   (byte) Volume type: bit 0: On; 1: Sustain; 2: Loop
  90.    !    +234      1   (byte) Panning type: bit 0: On; 1: Sustain; 2: Loop
  91.    !    +235      1   (byte) Vibrato type
  92.    !    +236      1   (byte) Vibrato sweep
  93.    !    +237      1   (byte) Vibrato depth
  94.    !    +238      1   (byte) Vibrato rate
  95.    !    +239      2   (word) Volume fadeout
  96.    !    +241      2   (word) Reserved
  97.    !
  98.    !                         Sample headers:
  99.    !                         ---------------
  100.    !
  101.    !       ?      4  (dword) Sample length
  102.    !      +4      4  (dword) Sample loop start
  103.    !      +8      4  (dword) Sample loop length
  104.    !     +12      1   (byte) Volume
  105.    !     +13      1   (byte) Finetune (signed byte -16..+15)
  106.    !     +14      1   (byte) Type: Bit 0-1: 0 = No loop, 1 = Forward loop,
  107.    !                                        2 = Ping-pong loop;
  108.    !                                     4: 16-bit sampledata
  109.    !     +15      1   (byte) Panning (0-255)
  110.    !     +16      1   (byte) Relative note number (signed byte)
  111.    !     +17      1   (byte) Reserved
  112.    !     +18     22   (char) Sample name
  113.    !
  114.    !                         Sample data:
  115.    !                         ------------
  116.    !
  117.    !       ?      ?          Sample data (signed): The samples are stored
  118.    !                         as delta values. To convert to real data:
  119.    !
  120.    !                         old=0;
  121.    !                         for i=1 to len
  122.    !                            new=sample[i]+old;
  123.    !                            sample[i]=new;
  124.    !                            old=new;
  125.  
  126.  
  127.  
  128.    ***********************
  129.    *   Pattern format:   *
  130.    ***********************
  131.  
  132.    The patterns are stored as ordinary MOD patterns, except that each
  133.    note is stored as 5 bytes:
  134.  
  135.       ?      1   (byte) Note (0-71, 0 = C-0)
  136.      +1      1   (byte) Instrument (0-128)
  137.      +2      1   (byte) Volume column byte (see below)
  138.      +3      1   (byte) Effect type
  139.      +4      1   (byte) Effect parameter
  140.  
  141.    A simle packing scheme is also adopted, so that the patterns not become
  142.    TOO large: Since the MSB in the note value is never used, if is used for
  143.    the compression. If the bit is set, then the other bits are interpreted
  144.    as follows:
  145.  
  146.       bit 0 set: Note follows
  147.           1 set: Instrument follows
  148.           2 set: Volume column byte follows
  149.           3 set: Effect follows
  150.           4 set: Guess what!
  151.  
  152.    It is very simple, but far from optimal. If you want a better,
  153.    you can always repack the patterns in your loader.
  154.  
  155.  
  156.  
  157.    ******************************
  158.    *   Volumes and envelopes:   *
  159.    ******************************
  160.  
  161.    The volume formula:
  162.  
  163.    FinalVol=(FadeOutVol/65536)*(EnvelopeVol/64)*(GlobalVol/64)*(Vol/64)*Scale;
  164.  
  165.    The panning formula:
  166.  
  167.    FinalPan=Pan+(EnvelopePan-32)*(128-Abs(Pan-128))/32;
  168.  
  169.       Envelope:
  170.       ---------
  171.  
  172.    The envelopes are processed once per frame, instead of every frame where
  173.    no new notes are read. This is also true for the instrument vibrato and
  174.    the fadeout. Since I am so lazy and the tracker is rather self-explaining
  175.    I am not going to write any more for the moment.
  176.  
  177.  
  178.    ********************************
  179.    *   Periods and frequencies:   *
  180.    ********************************
  181.  
  182.    PatternNote = 0..95 (0 = C-0, 95 = B-7)
  183.  
  184.    FineTune = -128..+127 (-128 = -1 halftone, +127 = +127/128 halftones)
  185.    RelativeTone = -96..95 (0 => C-4 = C-4)
  186.  
  187.    RealNote = PatternNote + RelativeTone; (0..118, 0 = C-0, 118 = A#9)
  188.  
  189.       Linear frequence table:
  190.       -----------------------
  191.  
  192.    Period = 10*12*16*4 - Note*16*4 - FineTune/2;
  193.    Frequency = 8363*2^((6*12*16*4 - Period) / (12*16*4));
  194.  
  195.       Amiga frequence table:
  196.       ----------------------
  197.  
  198.    Period = (PeriodTab[(Note MOD 12)*8 + FineTune/16]*(1-Frac(FineTune/16)) +
  199.              PeriodTab[(Note MOD 12)*8 + FineTune/16]*(Frac(FineTune/16)))
  200.             *16/2^(Note DIV 12);
  201.       (The period is interpolated for finer finetune values)
  202.    Frequency = 8363*1712/Period;
  203.  
  204.    PeriodTab = Array[0..12*8-1] of Word = (
  205.       907,900,894,887,881,875,868,862,856,850,844,838,832,826,820,814,
  206.       808,802,796,791,785,779,774,768,762,757,752,746,741,736,730,725,
  207.       720,715,709,704,699,694,689,684,678,675,670,665,660,655,651,646,
  208.       640,636,632,628,623,619,614,610,604,601,597,592,588,584,580,575,
  209.       570,567,563,559,555,551,547,543,538,535,532,528,524,520,516,513,
  210.       508,505,502,498,494,491,487,484,480,477,474,470,467,463,460,457);
  211.  
  212.  
  213.    *************************
  214.    *   Standard effects:   *
  215.    *************************
  216.  
  217.       0      Appregio
  218.       1  (*) Porta up
  219.       2  (*) Porta down
  220.       3  (*) Tone porta
  221.       4  (*) Vibrato
  222.       5  (*) Tone porta+Volume slide
  223.       6  (*) Vibrato+Volume slide
  224.       7  (*) Tremolo
  225.       8      Set panning
  226.       9      Sample offset
  227.       A  (*) Volume slide
  228.       B      Position jump
  229.       C      Set volume
  230.       D      Pattern break
  231.       E1 (*) Fine porta up
  232.       E2 (*) Fine porta down
  233.       E3     Set gliss control
  234.       E4     Set vibrato control
  235.       E5     Set finetune
  236.       E6     Set loop begin/loop
  237.       E7     Set tremolo control
  238.       E9     Retrig note
  239.       EA (*) Fine volume slide up
  240.       EB (*) Fine volume slide down
  241.       EC     Note cut
  242.       ED     Note delay
  243.       EE     Pattern delay
  244.       F      Set tempo/BPM
  245.       G      Set global volume
  246.       H  (*) Global volume slide
  247.       K      Key off
  248.       L      Set envelope position
  249.       P  (*) Panning slide
  250.       R  (*) Multi retrig note
  251.       T      Tremor
  252.       X1 (*) Extra fine porta up
  253.       X2 (*) Extra fine porta down
  254.  
  255.       (*) = If the command byte is zero, the last nonzero byte for the
  256.             command should be used.
  257.  
  258.    *********************************
  259.    *   Effects in volume column:   *
  260.    *********************************
  261.  
  262.    All effects in the volume column should work as the standard effects.
  263.    The volume column is interpreted before the standard effects, so
  264.    some standard effects may override volume column effects.
  265.  
  266.    Value      Meaning
  267.  
  268.       0       Do nothing
  269.     $10-$50   Set volume Value-$10
  270.       :          :        :
  271.       :          :        :
  272.     $60-$6f   Volume slide down
  273.     $70-$7f   Volume slide up
  274.     $80-$8f   Fine volume slide down
  275.     $90-$9f   Fine volume slide up
  276.     $a0-$af   Set vibrato speed
  277.     $b0-$bf   Vibrato
  278.     $c0-$cf   Set panning
  279.     $d0-$df   Panning slide left
  280.     $e0-$ef   Panning slide right
  281.     $f0-$ff   Tone porta
  282.  
  283.  
  284.  ============================================================================
  285. */
  286.  
  287. #if defined(powerc) || defined(__powerc)
  288. #pragma options align=mac68k
  289. #endif
  290.  
  291. #define UWORD unsigned short
  292. #define ULONG unsigned long
  293. #define UBYTE Byte
  294. #define BYTE char
  295. #define BOOL Boolean 
  296.  
  297. typedef struct XMHEADER{
  298.     char  id[17];                   // ID text: 'Extended module: '
  299.     char  songname[21];             // Module name, padded with zeroes and 0x1a at the end
  300.     char  trackername[20];          // Tracker name
  301.     UWORD version;                  // (word) Version number, hi-byte major and low-byte minor
  302.     ULONG headersize;               // Header size
  303.     UWORD songlength;               // (word) Song length (in patten order table)
  304.     UWORD restart;                  // (word) Restart position
  305.     UWORD numchn;                   // (word) Number of channels (2,4,6,8,10,...,32)
  306.     UWORD numpat;                   // (word) Number of patterns (max 256)
  307.     UWORD numins;                   // (word) Number of instruments (max 128)
  308.     UWORD flags;                    // (word) Flags: bit 0: 0 = Amiga frequency table (see below) 1 = Linear frequency table
  309.     UWORD tempo;                    // (word) Default tempo
  310.     UWORD bpm;                       // (word) Default BPM
  311.     UBYTE orders[256];              // (byte) Pattern order table
  312. } XMHEADER;
  313.  
  314.  
  315. typedef struct XMINSTHEADER{
  316.     ULONG size;                        // (dword) Instrument size
  317.     char  name[22];                 // (char) Instrument name
  318.     UBYTE type;                        // (byte) Instrument type (always 0)
  319.     UWORD numsmp;                   // (word) Number of samples in instrument
  320.     ULONG ssize;                    //
  321. } XMINSTHEADER;
  322.  
  323.  
  324. typedef struct XMPATCHHEADER{
  325.     
  326.     UBYTE what[96];         // (byte) Sample number for all notes
  327.     UWORD volenv[24];       // (byte) Points for volume envelope
  328.     UBYTE panenv[48];       // (byte) Points for panning envelope
  329.     UBYTE volpts;           // (byte) Number of volume points
  330.     UBYTE panpts;           // (byte) Number of panning points
  331.     UBYTE volsus;           // (byte) Volume sustain point
  332.     UBYTE volbeg;           // (byte) Volume loop start point
  333.     UBYTE volend;           // (byte) Volume loop end point
  334.     UBYTE pansus;           // (byte) Panning sustain point
  335.     UBYTE panbeg;           // (byte) Panning loop start point
  336.     UBYTE panend;           // (byte) Panning loop end point
  337.     UBYTE volflg;           // (byte) Volume type: bit 0: On; 1: Sustain; 2: Loop
  338.     UBYTE panflg;           // (byte) Panning type: bit 0: On; 1: Sustain; 2: Loop
  339.     UBYTE vibflg;           // (byte) Vibrato type
  340.     UBYTE vibsweep;         // (byte) Vibrato sweep
  341.     UBYTE vibdepth;         // (byte) Vibrato depth
  342.     UBYTE vibrate;          // (byte) Vibrato rate
  343.     UWORD volfade;          // (word) Volume fadeout
  344.     UWORD reserved[11];     // (word) Reserved
  345. } XMPATCHHEADER;
  346.  
  347.  
  348. typedef struct XMWAVHEADER{
  349.     ULONG length;           // (dword) Sample length
  350.     ULONG loopstart;        // (dword) Sample loop start
  351.     ULONG looplength;       // (dword) Sample loop length
  352.     UBYTE volume;           // (byte) Volume
  353.     BYTE finetune;          // (byte) Finetune (signed byte -128..+127)
  354.     UBYTE type;                     // (byte) Type: Bit 0-1: 0 = No loop, 1 = Forward loop,
  355.                                     // 2 = Ping-pong loop;
  356.                                     // 4: 16-bit sampledata
  357.     UBYTE panning;          // (byte) Panning (0-255)
  358.     BYTE  relnote;          // (byte) Relative note number (signed byte)
  359.     UBYTE reserved;         // (byte) Reserved
  360.     char  samplename[22];   // (char) Sample name
  361. } XMWAVHEADER;
  362.  
  363.  
  364. typedef struct XMPATHEADER{
  365.     ULONG size;                     // (dword) Pattern header length
  366.     UBYTE packing;                  // (byte) Packing type (always 0)
  367.     UWORD numrows;                  // (word) Number of rows in pattern (1..256)
  368.     UWORD packsize;                 // (word) Packed patterndata size
  369. } XMPATHEADER;
  370.  
  371. typedef struct MTMNOTE{
  372.     UBYTE a,b,c;
  373. } MTMNOTE;
  374.  
  375.  
  376. typedef struct XMNOTE{
  377.     UBYTE note,ins,vol,eff,dat;
  378. }XMNOTE;
  379.  
  380. #if defined(powerc) || defined(__powerc)
  381. #pragma options align=reset
  382. #endif